<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>护理不良事件上报表</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="../layui/layui.js"></script>
</head>
<body>
<form class="layui-form" lay-filter="FormLoad">

    <table border="1px" width="100%" cellpadding="0">
        <tr >
            <td colspan="6" style="text-align: center; height: 50px"> <span style=" font-size: 20px">护理不良事件报告表</span> </td>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td colspan="1" width="16.6%">
                    科室：
                </td>
                <td colspan="2" width="33.2%">
                    <input type="text" name="reporter_department" placeholder="" class="layui-input">
                </td>
                <td colspan="1" width="16.2%">
                    门诊号/住院号：
                </td>
                <td colspan="2" width="33.2%">
                    <input type="text" name="patient_num" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td colspan="1">
                    当事人：
                </td>
                <td colspan="2">
                    <input type="text" name="witness" placeholder="" class="layui-input">
                </td>
                <td colspan="1">
                    工作年限
                </td>
                <td colspan="2">
                    <input type="text" name="reporter_work_year" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td>
                    职称：
                </td>
                <td colspan="2">
                    <input type="text" name="reporter_profession" placeholder="" class="layui-input">
                </td>
                <td colspan="1">
                    报告人与其当事人的关系
                </td>
                <td colspan="2">
                    <input type="text" name="reporter_relation_patient" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td>
                    患者名字：
                </td>
                <td colspan="2">
                    <input type="text" name="patient_name" placeholder="" class="layui-input">
                </td>
                <td colspan="1">
                    诊断
                </td>
                <td colspan="2">
                    <input type="text" name="bad_event_diagnose" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>

        <tr>
            <div class="layui-form-item">
                <td>
                    发生时间：
                </td>
                <td colspan="2">
                    <input type="text" name="event_happen_time" id="event_happen_time" placeholder="" class="layui-input">
                </td>
                <td colspan="1">
                    上报时间
                </td>
                <td colspan="2">
                    <input type="text" name="event_report_time" id="event_report_time" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td>
                    分级：
                </td>
                <td colspan="2">
                    <input type="text" name="bad_event_level" placeholder="" class="layui-input">
                </td>
                <td colspan="1">
                    报告人：
                </td>
                <td colspan="2">
                    <input type="text" name="reporter" placeholder="" class="layui-input">
                </td>
            </div>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td colspan="2">
                    发生经过(发生时间，地点，事件内容，产生后果，采取的补偿措施与结果)：
                </td>
                <td colspan="4">
                    <textarea name="bad_event_describe" style="height: 80px" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
                </td>
            </div>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td colspan="2">
                    科内讨论分析（原因，教训，性质，处理意见）
                </td>
                <td colspan="4">
                    <textarea name="department_analyse" style="height: 80px"  placeholder="请输入" class="layui-textarea"></textarea>
                </td>
            </div>
        </tr>
        <tr>
            <div class="layui-form-item">
                <td colspan="2">
                    护理部质量安全会议及处理意见
                </td>
                <td colspan="4">
                    <textarea name="nurse_department_analyse" style="height: 50px"  placeholder="请输入" class="layui-textarea"></textarea>
                </td>
            </div>
        </tr>

    </table>
    <div class="layui-form-item">
        <div class="layui-input-block" style="text-align: center; margin-top: 50px">
            <button class="layui-btn" lay-submit lay-filter="YiLiaoqx">立即提交</button>
            <button class="layui-btn" lay-submit lay-filter="save">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>



<script>

    layui.use(['laydate','jquery','form','layedit','layer','table','laytpl'], function() {
        let $ = layui.jquery;
        let form = layui.form;
        let laydate = layui.laydate;
        var layer = layui.layer;
        var router = layui.router();
        laydate.render({
            elem: '#event_happen_time' //指定元素
            , type: 'date'
        });
        laydate.render({
            elem: '#event_report_time' //指定元素
            , type: 'date'
        });

        form.render();
        // 获取地址的中的值
        let user_code=decodeURIComponent(router.search.user_code);
        let user_name=decodeURIComponent(router.search.user_name);
        let dept_code=decodeURIComponent(router.search.dept_code);
        let dept_name=decodeURIComponent(router.search.dept_name);
        // layui data 保存数据
        if( user_code=="undefined"){
            console.log(layui.data('user').userinfo.user_name)
        } else{
            console.log(user_code);
            console.log("地址有值")
            layui.data('user', {
                key: 'userinfo',
                value:
                    {
                        user_name: user_name,
                        user_code: user_code,
                        dept_code:dept_code,
                        dept_name:dept_name
                    }
            });
            console.log(layui.data('user').userinfo.user_name)
        }
        //渲染 上报人和上报人单位
        form.val("FormLoad",{
            "reporter": layui.data('user').userinfo.user_name.replace(/\"/g, "") ,
            "reporter_department":layui.data('user').userinfo.dept_name.replace(/\"/g, "")
        })

        // submit 提交事件监听
        form.on('submit(YiLiaoqx)', function(data) {

            layer.confirm('确定提交吗？', {
                btn: ['确认', '取消'] //按钮
            }, function () {
                $.ajax({
                    url: '/event/event_insert',
                    type: "POST",
                    data:{
                        "reporter_code":layui.data('user').userinfo.user_code,
                        "reporter_name":layui.data('user').userinfo.user_name,
                        "dept_code":layui.data('user').userinfo.dept_code,
                        "dept_name":layui.data('user').userinfo.dept_name,
                        "event_code":12,
                        "reporter_department":data.field.reporter_department,
                        "patient_num":data.field.patient_num,
                        "witness":data.field.witness,
                        "reporter_work_year":data.field.reporter_work_year,
                        "reporter_profession":data.field.reporter_profession,
                        "reporter_relation_patient":data.field.reporter_relation_patient,
                        "patient_name":data.field.patient_name,
                        "bad_event_diagnose":data.field.bad_event_diagnose,
                        "event_happen_time":data.field.event_happen_time,
                        "event_report_time":data.field.event_report_time,
                        "bad_event_level":data.field.bad_event_level,
                        "reporter":data.field.reporter,
                        "bad_event_describe":data.field.bad_event_describe,
                        "department_analyse":data.field.department_analyse,
                        "nurse_department_analyse":data.field.nurse_department_analyse,
                        "status":2 //递交
                    },
                    success:function () {
                        layer.msg("保存成功");
                        form.val("FormLoad",{
                            "reporter_department":null,
                            "patient_num":null,
                            "witness":null,
                            "reporter_work_year":null,
                            "reporter_profession":null,
                            "reporter_relation_patient":null,
                            "patient_name":null,
                            "bad_event_diagnose":null,
                            "event_happen_time":null,
                            "event_report_time":null,
                            "bad_event_level":null,
                            "reporter":null,
                            "bad_event_describe":null,
                            "department_analyse":null,
                            "nurse_department_analyse":null,
                        })
                        form.render();
                    },
                })

            }, function () {
            });
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //save 保存事件监听
        form.on('submit(save)', function(data) {
            $.ajax({
                url: '/event/event_insert',
                type: "POST",
                data:{
                    "reporter_code":layui.data('user').userinfo.user_code,
                    "reporter_name":layui.data('user').userinfo.user_name,
                    "dept_code":layui.data('user').userinfo.dept_code,
                    "dept_name":layui.data('user').userinfo.dept_name,
                    "event_code":12,
                    "reporter_department":data.field.reporter_department,
                    "patient_num":data.field.patient_num,
                    "witness":data.field.witness,
                    "reporter_work_year":data.field.reporter_work_year,
                    "reporter_profession":data.field.reporter_profession,
                    "reporter_relation_patient":data.field.reporter_relation_patient,
                    "patient_name":data.field.patient_name,
                    "bad_event_diagnose":data.field.bad_event_diagnose,
                    "event_happen_time":data.field.event_happen_time,
                    "event_report_time":data.field.event_report_time,
                    "bad_event_level":data.field.bad_event_level,
                    "reporter":data.field.reporter,
                    "bad_event_describe":data.field.bad_event_describe,
                    "department_analyse":data.field.department_analyse,
                    "nurse_department_analyse":data.field.nurse_department_analyse,
                    "status": 1//1表示保存，可修改
                },
                success:function () {
                    layer.msg("保存成功");
                    form.val("FormLoad",{
                        "reporter_department":null,
                        "patient_num":null,
                        "witness":null,
                        "reporter_work_year":null,
                        "reporter_profession":null,
                        "reporter_relation_patient":null,
                        "patient_name":null,
                        "bad_event_diagnose":null,
                        "event_happen_time":null,
                        "event_report_time":null,
                        "bad_event_level":null,
                        "reporter":null,
                        "bad_event_describe":null,
                        "department_analyse":null,
                        "nurse_department_analyse":null,
                    })
                    form.render();
                },
            });
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    })
</script>

</html>
